package com.school.controller;

import com.school.entity.Letter;
import com.school.service.LetterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/Letter")
public class LetterController {
    @Autowired
    LetterService service;

    // HttpServletRequest request, HttpServletResponse response

    @ResponseBody
    @RequestMapping("/insertOne.do")
    public String insertOne(String name, String phone, String context) {
        Letter letter = new Letter(name,phone,context);
        System.out.println("letter = " + letter);
        int i = service.insertOne(letter);
        if (i>0){
            return "success";
        }
        return "fail";
    }

    @ResponseBody
    @RequestMapping("/getAll.do")
    public Letter[] getAll() {
        Letter[] letters = service.selectAll();
        return letters;
    }

    @ResponseBody
    @RequestMapping("/getOne.do")
    public Letter getAll(String about_name) {
        Letter letter = service.selectOne(about_name);
        return letter;
    }
}
